home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / programr / atre27.exe / ATREE_27 / OCRDEMO2 / OCR.CPP < prev    next >
C/C++ Source or Header  |  1992-08-01  |  10KB  |  305 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** ocr.cpp                                                             ****
  4.  ****                                                                     ****
  5.  **** atree release 2.7 for Windows                                       ****
  6.  **** Adaptive Logic Network (ALN) simulation program.                    ****
  7.  **** Copyright (C) M. Thomas, N. Sanche, W.W. Armstrong 1991, 1992       ****
  8.  ****                                                                                       ****
  9.  **** License:                                                            ****
  10.  **** A royalty-free license is granted for the use of this software for  ****
  11.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  12.  **** modified provided this notice appears in its entirety and unchanged ****
  13.  **** in all derived source programs.  Persons modifying the code are     ****
  14.  **** requested to state the date, the changes made and who made them     ****
  15.  **** in the modification history.                                        ****
  16.  ****                                                                     ****
  17.  **** Patent License:                                                     ****
  18.  **** The use of a digital circuit which transmits a signal indicating    ****
  19.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  20.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  21.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  22.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES to    ****
  23.  **** adapt logic trees using this program and its modifications.         ****
  24.  ****                                                                     ****
  25.  **** Limited Warranty:                                                   ****
  26.  **** This software is provided "as is" without warranty of any kind,     ****
  27.  **** either expressed or implied, including, but not limited to, the     ****
  28.  **** implied warrantees of merchantability and fitness for a particular  ****
  29.  **** purpose.  The entire risk as to the quality and performance of the  ****
  30.  **** program is with the user.  Neither the authors, nor the             ****
  31.  **** University of Alberta, its officers, agents, servants or employees  ****
  32.  **** shall be liable or responsible in any way for any damage to         ****
  33.  **** property or direct personal or consequential injury of any nature   ****
  34.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  35.  **** or any other party as a consequence of the use or disposition of    ****
  36.  **** this software.                                                      ****
  37.  **** Modification history:                                               ****
  38.  ****                                                                     ****
  39.  **** 92.04.27 atree v2.5 for Windows, M. Thomas                          ****
  40.  **** 92.03.07 Release 2.6, Monroe Thomas, Neal Sanche                    ****
  41.  **** 92.01.08 Release 2.7, Monroe Thomas, Neal Sanche                    ****
  42.  ****                                                                     ****
  43.  *****************************************************************************/
  44.  
  45. #include "ocr.h"
  46. #include "editlett.h"
  47. #include "editscro.h"
  48.  
  49. _CLASSDEF(Tocrapp)
  50. class TOcrApp : public TApplication
  51. {
  52. public:
  53.     TOcrApp(LPSTR AName, HANDLE hInst, HANDLE hPrevInst,
  54.              LPSTR lpCmdLine, int nCmdShow) : TApplication(AName,
  55.              hInst, hPrevInst, lpCmdLine, nCmdShow) {};
  56.     virtual void InitMainWindow();
  57. };
  58.  
  59. //
  60. // Main Dialog methods
  61. //
  62.  
  63. TOcr::TOcr() : TDialog(NULL, OCR)
  64. {
  65.     randomize();
  66.  
  67.     shutdown = FALSE;
  68.  
  69.     Quit = new TBButton(this, OCR_QUIT);
  70.     Start = new TBButton(this, OCR_START);
  71.     Stop = new TBButton(this, OCR_STOP);
  72.     Train = new TBButton(this, OCR_TRAIN);
  73.     Reverse = new TBButton(this, OCR_REVERSE);
  74.     Forget = new TBButton(this, OCR_FORGET);
  75.     Reset = new TBButton(this, OCR_RESET);
  76.     EditA = new TBButton(this, OCR_EDITA);
  77.     EditL = new TBButton(this, OCR_EDITL);
  78.     EditN = new TBButton(this, OCR_EDITN);
  79.  
  80.     hLightOn = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LIGHTON));
  81.     hLightOff = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LIGHTOFF));
  82.     hLetterA = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LETTER_A));
  83.     hLetterL = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LETTER_L));
  84.     hLetterN = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LETTER_N));
  85.     hLetterClear = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(OCR_LETTER_CLEAR));
  86.  
  87.     Correct = new TBStatic(this, OCR_CORRECT, 9);
  88.     Incorrect = new TBStatic(this, OCR_INCORRECT, 9);
  89.     Status = new TBStatic(this, OCR_STATUS, 60);
  90.  
  91.     LetterBitmap = new TBitmapControl(this, OCR_BITMAP, hLetterA);
  92.     LightBulbA = new TBitmapControl(this, OCR_LIGHTBULB_A, hLightOff);
  93.     LightBulbL = new TBitmapControl(this, OCR_LIGHTBULB_L, hLightOff);
  94.     LightBulbN = new TBitmapControl(this, OCR_LIGHTBULB_N, hLightOff);
  95.     LetterA = new TBitmapControl(this, OCR_DRAW_A, hLetterA);
  96.     LetterL = new TBitmapControl(this, OCR_DRAW_L, hLetterL);
  97.     LetterN = new TBitmapControl(this, OCR_DRAW_N, hLetterN);
  98. }
  99.  
  100. TOcr::~TOcr()
  101. {
  102.     delete Quit;
  103.     delete Start;
  104.     delete Stop;
  105.     delete Train;
  106.     delete Reverse;
  107.     delete Forget;
  108.     delete Reset;
  109.     delete EditA;
  110.     delete EditL;
  111.     delete EditN;
  112.  
  113.     delete Correct;
  114.     delete Incorrect;
  115.     delete Status;
  116.  
  117.     DeleteObject(hLightOn);
  118.     DeleteObject(hLightOff);
  119.     DeleteObject(hLetterA);
  120.     DeleteObject(hLetterL);
  121.     DeleteObject(hLetterN);
  122.     DeleteObject(hLetterClear);
  123.  
  124.     delete LetterBitmap;
  125.     delete LightBulbA;
  126.     delete LightBulbL;
  127.     delete LightBulbN;
  128.     delete LetterA;
  129.     delete LetterL;
  130.     delete LetterN;
  131. }
  132.  
  133. LPSTR
  134. TOcr::GetClassName()
  135. {
  136.     return("bordlg_ocr");
  137. }
  138.  
  139. void
  140. TOcr::GetWindowClass(WNDCLASS& AWndClass)
  141. {
  142.     TDialog::GetWindowClass(AWndClass);
  143.     AWndClass.lpfnWndProc = BWCCDefDlgProc;
  144.     AWndClass.hIcon = LoadIcon(GetApplication()->hInstance, "atreeico");
  145.     AWndClass.cbWndExtra = DLGWINDOWEXTRA;
  146. }
  147.  
  148. void
  149. TOcr::SetupWindow()
  150. {
  151.     TDialog::SetupWindow();
  152.     Status->SetText("ALN Demo - Light flashes on under character ALN detects");
  153.     EnableWindow(Stop->HWindow, FALSE);
  154.  
  155.     LetterBitmap->SetDrawColor(RGB(0, 0, 255));
  156.     LetterBitmap->SetEraseColor(RGB(192, 192, 192));
  157.     LetterBitmap->Refresh();
  158.     LightBulbA->Refresh();
  159.     LightBulbL->Refresh();
  160.     LightBulbN->Refresh();
  161.     LetterA->SetDrawColor(RGB(0, 0, 255));
  162.     LetterA->SetEraseColor(RGB(192, 192, 192));
  163.     LetterA->Refresh();
  164.     LetterL->SetDrawColor(RGB(0, 0, 255));
  165.     LetterL->SetEraseColor(RGB(192, 192, 192));
  166.     LetterL->Refresh();
  167.     LetterN->SetDrawColor(RGB(0, 0, 255));
  168.     LetterN->SetEraseColor(RGB(192, 192, 192));
  169.     LetterN->Refresh();
  170.  
  171.     write_default();
  172.  
  173.     hSysMenu = GetSystemMenu(HWindow, FALSE);
  174. }
  175.  
  176. BOOL
  177. TOcr::CanClose()
  178. {
  179.     stop = TRUE;
  180.     shutdown = TRUE;
  181.     WinHelp(HWindow, "atree.hlp", HELP_QUIT, NULL);
  182. //    remove("ocr.tre");
  183.     return(TRUE);
  184. }
  185.  
  186. void
  187. TOcr::OcrAbout()
  188. {
  189.     GetApplication()->ExecDialog(new TDialog(this, OCR_ABOUTDLG));
  190. }
  191.  
  192. void
  193. TOcr::OcrQuit()
  194. {
  195.     CloseWindow();
  196. }
  197.  
  198. void
  199. TOcr::OcrHelp()
  200. {
  201.     WinHelp(HWindow, "atree.hlp", HELP_CONTEXT, 30L);
  202. }
  203.  
  204. void
  205. TOcr::OcrReset()
  206. {
  207.     LetterA->Init(hLetterA);
  208.     LetterA->SetDrawColor(RGB(0, 0, 255));
  209.     LetterA->SetEraseColor(RGB(192, 192, 192));
  210.     LetterA->Refresh();
  211.     LetterL->Init(hLetterL);
  212.     LetterL->SetDrawColor(RGB(0, 0, 255));
  213.     LetterL->SetEraseColor(RGB(192, 192, 192));
  214.     LetterL->Refresh();
  215.     LetterN->Init(hLetterN);
  216.     LetterN->SetDrawColor(RGB(0, 0, 255));
  217.     LetterN->SetEraseColor(RGB(192, 192, 192));
  218.     LetterN->Refresh();
  219.     write_default();
  220. }
  221.  
  222. void
  223. TOcr::OcrStop()
  224. {
  225.     stop = TRUE;
  226. }
  227.  
  228. void
  229. TOcr::OcrForget()
  230. {
  231.     LPATREE atree;
  232.     FILE* outstream;
  233.     WORD width = LetterBitmap->GetWidthBytes();
  234.  
  235.     Status->SetText("Selecting YES means you will need to retrain in the future!");
  236.     int result = BWCCMessageBox(HWindow, "Forget previous training?", "OCR Forget",
  237.                             MB_ICONQUESTION | MB_YESNOCANCEL);
  238.  
  239.     if (result != IDYES) return;
  240.  
  241.     Status->SetText("ALN Demo - Light flashes on under character ALN detects");
  242.  
  243.     if ((outstream = fopen("ocr.tre", "w")) == NULL)
  244.     {
  245.         BWCCMessageBox(HWindow, "Can't open 'ocr.tre'", "OCR Train",
  246.                          MB_ICONEXCLAMATION | MB_OK);
  247.         exit(0);
  248.     }
  249.  
  250.     fprintf(outstream, "1\n");
  251.  
  252.     for (WORD i = 0; i < 3; i++)
  253.     {
  254.         atree = atree_create(width*8, 512);
  255.         atree_write(outstream, atree);
  256.         atree_free(atree);
  257.     }
  258.  
  259.     fclose(outstream);
  260. }
  261.  
  262. void
  263. TOcr::OcrEditA()
  264. {
  265.     PTEditDlg EditCharDlg;
  266.  
  267.     EditCharDlg = new TEditDlg(this, (PTBitmapControl)LetterA);
  268.     GetApplication()->ExecDialog(EditCharDlg);
  269. }
  270.  
  271. void
  272. TOcr::OcrEditL()
  273. {
  274.     PTEditDlg EditCharDlg;
  275.  
  276.     EditCharDlg = new TEditDlg(this, (PTBitmapControl)LetterL);
  277.     GetApplication()->ExecDialog(EditCharDlg);
  278.  
  279. }
  280.  
  281. void
  282. TOcr::OcrEditN()
  283. {
  284.     PTEditDlg EditCharDlg;
  285.  
  286.     EditCharDlg = new TEditDlg(this, (PTBitmapControl)LetterN);
  287.     GetApplication()->ExecDialog(EditCharDlg);
  288.  
  289. }
  290.  
  291. void TOcrApp::InitMainWindow()
  292. {
  293.     MainWindow = new TOcr();
  294. }
  295.  
  296. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  297.            LPSTR lpCmd, int nCmdShow)
  298. {
  299.   TOcrApp OcrApp("OCR", hInstance, hPrevInstance,
  300.         lpCmd, nCmdShow);
  301.     BWCCGetVersion();
  302.     OcrApp.Run();
  303.   return OcrApp.Status;
  304. }
  305.